'use strict';

import React, {
    Component,
    PropTypes
} from 'react';

import ReactDOM, {
    render
} from 'react-dom';
export default class Popup extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    yes_cb() {
        this.props.config.yes_cb();
    }
    no_cb() {
        this.props.config.no_cb();
    }
    componentWillReceiveProps() {
        setTimeout(function() {
            this.setState({
                blockOrNone: this.props.blockOrNone,
                _flag: this.props._flag
            })
        }.bind(this), 0)
    }

    render() {
        var {
            config
        } = this.props;
        const {
            isSure,
            isCancel
        } = config;
        const {
            blockOrNone,
            _flag
        } = this.state;
        return (
            <div className="none" style={{
                display: (!!blockOrNone && !!_flag)
                    ? 'block'
                    : 'none'
            }}>
                <div className="popup_zindex"></div>
                <div className="popup_content" style={{
                        top:config.newTop?config.newTop:null
                    }}>
                    <div className="header">
                        <div className="popup_title">{config.tip || '温馨提示'}</div>
                    </div>
                    <div className="popup_content2" dangerouslySetInnerHTML={{__html:config.content}} ></div>
                    <div className="foot">
                        <div className="btn cancel_btn" style={{
                            display: isCancel
                                ? 'none'
                                : 'flex',
                                color: '#666'
                        }} onClick={this.no_cb.bind(this)}>{config.no}</div>
                    {config.yes?<div className="btn sure_btn" style={{
                            display: isSure
                                ? 'none'
                                : 'flex'
                        }} onClick={this.yes_cb.bind(this)}>{config.yes}</div>:null}
                    </div>
                </div>
            </div>
        )
    }
}
